package shop.util;

import java.io.IOException;
import java.io.InputStream;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

public class SqlSessionUtil {
	public SqlSession getSqlSession(){
		InputStream in = null;
		SqlSession se = null;
		try {
			//读取配置文件
			 in = Resources.getResourceAsStream("SqlMapConfig.xml");
			 //创建sqlsession工厂
			 SqlSessionFactory build = new SqlSessionFactoryBuilder().build(in);
			 //打开工厂
			 se = build.openSession();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return se;
	}
}
